//
//  UIButton+MyButton.m
//  lianxi
//
//  Created by wang on 15-3-31.
//  Copyright (c) 2015年 wang. All rights reserved.
//

#import "UIButton+MyButton.h"

@implementation UIButton (MyButton)
//只适用于custom的
- (void) getMyBtnWithTitle:(NSString *)title andLeftIma:(NSArray *)imaName
{
    [self setTitle:title forState:UIControlStateNormal];
    [self setImage:[UIImage imageNamed:[imaName firstObject]] forState:UIControlStateNormal];
    if (imaName.count==2) {
        [self setImage:[UIImage imageNamed:[imaName lastObject]] forState:UIControlStateHighlighted];
    }
    [self setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
//    NSDictionary *dict=@{NSFontAttributeName:self.titleLabel.font};
//    CGSize size1=[self.titleLabel.text boundingRectWithSize:CGSizeMake(300, 100) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
//    CGSize size2=[UIImage imageNamed:[imaName firstObject]].size;
    
    [self setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    [self setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    //self.bounds=CGRectMake(0, 0, size1.width+size2.width, self.bounds.size.height);
    [self sizeToFit];
}
+(UIButton *)getHomeAppliancesBtnWith:(NSString *)title andHeight:(float)height andNormalColor:(UIColor *)color andSelectColor:(UIColor *)color_ andNormalFont:(UIFont *)font andSlectFont:(UIFont *)font_
{
    if (title.length>0) {
        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:title forState:UIControlStateNormal];
        [btn setTitleColor:color forState:UIControlStateNormal];
        [btn setTitleColor:color_ forState:UIControlStateSelected];
        btn.titleLabel.font=font;
        NSDictionary *dict=@{NSFontAttributeName:font};
        CGSize size=[title boundingRectWithSize:CGSizeMake(300, 100) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
        btn.bounds=CGRectMake(0, 0, size.width+35, 40);
        return btn;
    }
    return nil;
}
- (void) getMyBtnWithTitle:(NSString *)title andRightIma:(NSArray *)imaName
{
    [self setTitle:title forState:UIControlStateNormal];
    [self setImage:[UIImage imageNamed:[imaName firstObject]] forState:UIControlStateNormal];
    if (imaName.count==2) {
        [self setImage:[UIImage imageNamed:[imaName lastObject]] forState:UIControlStateHighlighted];
    }
    [self setTitleColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];
    NSDictionary *dict=@{NSFontAttributeName:self.titleLabel.font};
    CGSize size1=[self.titleLabel.text boundingRectWithSize:CGSizeMake(300, 100) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
    CGSize size2=[UIImage imageNamed:[imaName firstObject]].size;
    NSLog(@"%f",size2.width);
    [self setTitleEdgeInsets:UIEdgeInsetsMake(0, -size2.width, 0, size2.width)];
    [self setImageEdgeInsets:UIEdgeInsetsMake(0, size1.width, 0, -size1.width)];
//    float maxHeight = size1.height>size2.height?size1.height:size2.height;
//    self.bounds=CGRectMake(0, 0, size1.width+size2.width, self.bounds.size.height>maxHeight?self.bounds.size.height:maxHeight);
    [self sizeToFit];
}


@end
